https://leetcode.cn/problems/reverse-nodes-in-k-group/description/
class Solution {
public:
    ListNode* reverseKGroup(ListNode* head, int k) {
        if(head==nullptr||head->next==nullptr)  return head;
        //计算需要n轮翻转
        int n=0;
        ListNode*ncur=head;
        while(ncur)
        {
            ncur=ncur->next;
            ++n;
        }
        n/=k;

        ListNode *newnode=new ListNode(0);
        ListNode *cur=head,*prev=newnode;
        while(n--)
        {
            int count=k;
            ListNode*tmp=cur;
            while(count--)
            {
                ListNode*next=cur->next;
                cur->next=prev->next;
                prev->next=cur;  
                cur=next;
                
            }
            prev=tmp;
            cout<<prev->val<<endl;
        }


        //链接剩下部分
        prev->next=cur;
        
        if(newnode->next)
        cur=newnode->next;
        delete newnode;
        return cur;
    }
};